package com.example.bishe.web.c.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.bishe.entity.Approval;
import com.example.bishe.service.ApprovalService;
import com.example.bishe.util.RestResult;
import com.example.bishe.web.c.vo.UserApprovalVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 功能描述
 *
 * @author: LDH
 * @date: 2023年04月23日 18:27
 */
@RestController
@Api(value = "客户端查询", tags = {"用户通知消息"})
@RequestMapping("/c/approval")
public class CApprovalController {

    @Autowired
    private ApprovalService approvalService;

    @ApiOperation("用户查询空间加入申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query")
    })
    @GetMapping("/page")
    public RestResult<IPage<UserApprovalVO>> page(
            @RequestParam(required = false,defaultValue = "1")  int pageNum,
            @RequestParam(required = false,defaultValue = "10") int pageSize,
            @RequestParam(required = false) Long userId
    ){
        return RestResult.get_success(approvalService.getUserApproval(pageNum,pageSize,userId));
    }

    @ApiOperation("用户同意或拒绝用户加入空间")
    @PutMapping("/update")
    public RestResult<Void> update(@RequestBody Approval approval){
        approvalService.doApply(approval);
        return RestResult.set_success("审批成功");
    }



}